home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- //////////////////////////////////////////////////////////////////////
- // Connect.c++ - definition of the connect class
- //
- // This class defines a connect stretch of road. It is
- // derived from the stretch abstract base class.
- //////////////////////////////////////////////////////////////////////
-
- #include <math.h>
- #include "Stretch.h"
- #include "Connect.h"
-
- Connect::Connect(Stretch *prev, Stretch *next)
- : Stretch(prev, next)
- {
- if (!prev || !next)
- {
- fprintf(stderr,"Connect stretches must have a prev and a next\n");
- exit(-1);
- }
-
- _type = CONNECT;
- _step = 30.0;
-
- _turn_angle = _turn_radius = 0.0; // straights do not curve
- _hill_angle = _hill_radius = _bank_angle = 0.0;
-
- _length=
- (_prev->get_middle(_prev->get_count()-1)
- - _next->get_middle(0)).length();
-
- _width = _prev->get_side_direction(_prev->get_count()-1,LEFT).length();
-
- Stretch::compute_step();
- Stretch::allocate_data();
-
- // find the accumulated offset and orientation
- SbVec3f prev_offset;
- SbRotation prev_orientation;
- Stretch::find_previous(prev_offset, prev_orientation);
-
- make_connect(prev_orientation);
-
- Stretch::init_scenery();
- }
-
-
- Connect::~Connect()
- {
- }
-
-
- void Connect::make_connect(SbRotation prev_orientation)
- {
- for (int j = 0; j < _num_markers; j++)
- {
- float interp = (float)j/(float)(_num_markers - 1);
-
- _data[j].left =
- (1.0 - interp)*_prev->get_left(_prev->get_count()-1) +
- interp* _next->get_left(0);
-
- _data[j].middle =
- (1.0 - interp)*_prev->get_middle(_prev->get_count()-1) +
- interp* _next->get_middle(0);
-
- _data[j].right =
- (1.0 - interp)*_prev->get_right(_prev->get_count()-1) +
- interp* _next->get_right(0);
-
- _data[j].normal =
- (1.0 - interp)*_prev->get_normal(_prev->get_count()-1) +
- interp* _next->get_normal(0);
-
- // median
- _median_data[j].left =
- _data[j].left + (1.0-STRIPE_WIDTH)*(_data[j].middle - _data[j].left);
-
- _median_data[j].right =
- _data[j].middle + STRIPE_WIDTH*(_data[j].right - _data[j].middle);
-
- _median_data[j].left += STRIPE_HEIGHT*_data[j].normal;
- _median_data[j].right += STRIPE_HEIGHT*_data[j].normal;
-
- // terrain
- _left_terrain_data[j].left =
- _data[j].left + TERRAIN_WIDTH*(_data[j].left - _data[j].middle);
- _left_terrain_data[j].right = _data[j].left;
-
- _right_terrain_data[j].right =
- _data[j].middle + TERRAIN_WIDTH*(_data[j].right - _data[j].middle);
- _right_terrain_data[j].left = _data[j].right;
- }
-
- // offset from origin to end of this stretch
- _offset = _data[_num_markers-1].middle;
-
- SbRotation this_quat(_data[0].normal,_data[_num_markers - 1].normal);
- _orientation = this_quat * prev_orientation;
- }
-
-